//
//  UITableView+BackImage.m
//  KoalaPhoto
//
//  Created by 张英堂 on 15/1/22.
//  Copyright (c) 2015年 visionhacker. All rights reserved.
//

#import "UITableView+BackImage.h"
#import "YTMacro.h"

@implementation UITableView (BackImage)

- (void)setBackImageWithName:(NSString *)imageName{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    
    CGRect rect = CGRectMake((WIN_WIDTH - 200)/2, (self.frame.size.height -200)/2, 200, 200);
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
    [imageView setContentMode:UIViewContentModeScaleAspectFit];
    [imageView setClipsToBounds:YES];
    [imageView setImage:image];
    
    UIView *view = self.backgroundView;
    if (view == nil) {
        self.backgroundView = imageView;
    }else{
        [view addSubview:imageView];
    }
    
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)removeBackImage{
    UIView *view = self.backgroundView;
    [view removeFromSuperview];
    view = nil;
}

@end
